package com.sponge.contract;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.web3j.abi.EventEncoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.Event;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.abi.datatypes.generated.Uint8;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.methods.request.EthFilter;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tx.Contract;
import org.web3j.tx.TransactionManager;
import rx.Observable;
import rx.functions.Func1;

/**
 * <p>Auto generated code.
 * <p><strong>Do not modify!</strong>
 * <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
 * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the 
 * <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
 *
 * <p>Generated with web3j version 3.5.0.
 */
public class Credit_sol_Credit extends Contract {
    private static final String BINARY = "608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550611083806100606000396000f3006080604052600436106100a4576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063165512e5146100a957806317c8aa77146101655780636516bd5b146102215780639046f4081461027857806391a4def71461033e578063a4ee0d8f146103fa578063ae0f12bd1461045f578063b6daea6c1461051b578063deaf10be146105d7578063e88f3ea314610693575b600080fd5b3480156100b557600080fd5b506100ea600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506106f8565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561012a57808201518184015260208101905061010f565b50505050905090810190601f1680156101575780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561017157600080fd5b506101a6600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610742565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101e65780820151818401526020810190506101cb565b50505050905090810190601f1680156102135780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561022d57600080fd5b50610262600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061078c565b6040518082815260200191505060405180910390f35b34801561028457600080fd5b506102c3600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610922565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103035780820151818401526020810190506102e8565b50505050905090810190601f1680156103305780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561034a57600080fd5b5061037f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610af1565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103bf5780820151818401526020810190506103a4565b50505050905090810190601f1680156103ec5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561040657600080fd5b5061043b600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610bdd565b6040518082600381111561044b57fe5b60ff16815260200191505060405180910390f35b34801561046b57600080fd5b506104a0600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c33565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156104e05780820151818401526020810190506104c5565b50505050905090810190601f16801561050d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561052757600080fd5b5061055c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d99565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561059c578082015181840152602081019050610581565b50505050905090810190601f1680156105c95780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156105e357600080fd5b50610618600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610de3565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561065857808201518184015260208101905061063d565b50505050905090810190601f1680156106855780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561069f57600080fd5b506106d4600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ed6565b604051808260028111156106e457fe5b60ff16815260200191505060405180910390f35b6060610705826002610f2f565b6040805190810160405280600e81526020017f63616e63656c20737563636573730000000000000000000000000000000000008152509050919050565b606061074f826003610f2f565b6040805190810160405280600e81526020017f64656c65746520737563636573730000000000000000000000000000000000008152509050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16148061084b5750600160038111156107f157fe5b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16600381111561084957fe5b145b1561089a57600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010154905061091d565b8173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561091857600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010154905061091d565b600090505b919050565b60606001600381111561093157fe5b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16600381111561098957fe5b1415156109fe576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260118152602001807f5065726d697373696f6e2064656e69656400000000000000000000000000000081525060200191505060405180910390fd5b81600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fe5404b3a7d3b1961c295f51694bc9d447ed6e512991ca92cd00090862f9d28ae846040518082815260200191505060405180910390a36040805190810160405280600e81526020017f6d6f646966792073756363657373000000000000000000000000000000000000815250905092915050565b60606000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160006101000a81548160ff02191690836002811115610b5257fe5b0217905550610258600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101819055506040805190810160405280600b81526020017f61646420737563636573730000000000000000000000000000000000000000008152509050919050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b60606000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610cf9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260118152602001807f5065726d697373696f6e2064656e69656400000000000000000000000000000081525060200191505060405180910390fd5b60028060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160006101000a81548160ff02191690836002811115610d5757fe5b02179055506040805190810160405280601381526020017f637265646974207573657220656d6572676564000000000000000000000000008152509050919050565b6060610da6826000610f2f565b6040805190810160405280600b81526020017f61646420737563636573730000000000000000000000000000000000000000008152509050919050565b606060006003811115610df257fe5b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166003811115610e4a57fe5b1415610e9857610e5b826001610f2f565b6040805190810160405280601281526020017f617574686f72697a6564207375636365737300000000000000000000000000008152509050610ed1565b6040805190810160405280600d81526020017f756e6b6e6f77206167656e63790000000000000000000000000000000000000081525090505b919050565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160009054906101000a900460ff169050919050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610ff3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260118152602001807f5065726d697373696f6e2064656e69656400000000000000000000000000000081525060200191505060405180910390fd5b80600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083600381111561104e57fe5b021790555050505600a165627a7a723058203bdc66ed3433966689d4e3097950bfc5c82cb0d6e1c8f8c33ac65a843d6d46820029";

    public static final String FUNC_CANCELAGENCY = "cancelAgency";

    public static final String FUNC_DELETEAGENCY = "deleteAgency";

    public static final String FUNC_QUERYUSERCREDIT = "queryUserCredit";

    public static final String FUNC_MODIFYUSERCREDIT = "modifyUserCredit";

    public static final String FUNC_ADDCREDITUSER = "addCreditUser";

    public static final String FUNC_QUERYAGENCYSTATUS = "queryAgencyStatus";

    public static final String FUNC_EMERGENCYCREDITUSER = "emergencyCreditUser";

    public static final String FUNC_ADDAGENCY = "addAgency";

    public static final String FUNC_AUTHORIZEAGENCY = "authorizeAgency";

    public static final String FUNC_QUERYUSERSTATUS = "queryUserStatus";

    public static final Event MODIFYCREDIT_EVENT = new Event("modifyCredit", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}),Arrays.asList(new TypeReference<Uint256>() {}));
    ;

    protected Credit_sol_Credit(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    protected Credit_sol_Credit(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

    public RemoteCall<TransactionReceipt> cancelAgency(String agency) {
        final Function function = new Function(
                FUNC_CANCELAGENCY, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(agency)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteCall<TransactionReceipt> deleteAgency(String agency) {
        final Function function = new Function(
                FUNC_DELETEAGENCY, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(agency)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteCall<BigInteger> queryUserCredit(String user) {
        final Function function = new Function(FUNC_QUERYUSERCREDIT, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(user)), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
        return executeRemoteCallSingleValueReturn(function, BigInteger.class);
    }

    public RemoteCall<TransactionReceipt> modifyUserCredit(String user, BigInteger creditValue) {
        final Function function = new Function(
                FUNC_MODIFYUSERCREDIT, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(user), 
                new org.web3j.abi.datatypes.generated.Uint256(creditValue)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteCall<TransactionReceipt> addCreditUser(String user) {
        final Function function = new Function(
                FUNC_ADDCREDITUSER, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(user)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteCall<BigInteger> queryAgencyStatus(String agency) {
        final Function function = new Function(FUNC_QUERYAGENCYSTATUS, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(agency)), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Uint8>() {}));
        return executeRemoteCallSingleValueReturn(function, BigInteger.class);
    }

    public RemoteCall<TransactionReceipt> emergencyCreditUser(String user) {
        final Function function = new Function(
                FUNC_EMERGENCYCREDITUSER, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(user)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteCall<TransactionReceipt> addAgency(String agency) {
        final Function function = new Function(
                FUNC_ADDAGENCY, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(agency)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteCall<TransactionReceipt> authorizeAgency(String agency) {
        final Function function = new Function(
                FUNC_AUTHORIZEAGENCY, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(agency)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteCall<BigInteger> queryUserStatus(String user) {
        final Function function = new Function(FUNC_QUERYUSERSTATUS, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(user)), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Uint8>() {}));
        return executeRemoteCallSingleValueReturn(function, BigInteger.class);
    }

    public static RemoteCall<Credit_sol_Credit> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return deployRemoteCall(Credit_sol_Credit.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
    }

    public static RemoteCall<Credit_sol_Credit> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return deployRemoteCall(Credit_sol_Credit.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "");
    }

    public List<ModifyCreditEventResponse> getModifyCreditEvents(TransactionReceipt transactionReceipt) {
        List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(MODIFYCREDIT_EVENT, transactionReceipt);
        ArrayList<ModifyCreditEventResponse> responses = new ArrayList<ModifyCreditEventResponse>(valueList.size());
        for (Contract.EventValuesWithLog eventValues : valueList) {
            ModifyCreditEventResponse typedResponse = new ModifyCreditEventResponse();
            typedResponse.log = eventValues.getLog();
            typedResponse.agency = (String) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.user = (String) eventValues.getIndexedValues().get(1).getValue();
            typedResponse.creditValue = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
            responses.add(typedResponse);
        }
        return responses;
    }

    public Observable<ModifyCreditEventResponse> modifyCreditEventObservable(EthFilter filter) {
        return web3j.ethLogObservable(filter).map(new Func1<Log, ModifyCreditEventResponse>() {
            @Override
            public ModifyCreditEventResponse call(Log log) {
                Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(MODIFYCREDIT_EVENT, log);
                ModifyCreditEventResponse typedResponse = new ModifyCreditEventResponse();
                typedResponse.log = log;
                typedResponse.agency = (String) eventValues.getIndexedValues().get(0).getValue();
                typedResponse.user = (String) eventValues.getIndexedValues().get(1).getValue();
                typedResponse.creditValue = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
                return typedResponse;
            }
        });
    }

    public Observable<ModifyCreditEventResponse> modifyCreditEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
        EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
        filter.addSingleTopic(EventEncoder.encode(MODIFYCREDIT_EVENT));
        return modifyCreditEventObservable(filter);
    }

    public static Credit_sol_Credit load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return new Credit_sol_Credit(contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    public static Credit_sol_Credit load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return new Credit_sol_Credit(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

    public static class ModifyCreditEventResponse {
        public Log log;

        public String agency;

        public String user;

        public BigInteger creditValue;
    }
}
